/**
 * 管理用户列表
 */

import { UserType } from "../../api/user"
import { SET_USERLIST, USRE_SUCCESS, USRE_ERROR } from "../actions/user.action"

export interface UserState {
    userList: UserType[],
    total: number,
    loading: boolean,
    errMsg: string
} 

const initialState: UserState = {
    userList: [], // 用户列表
    total: 0, // 总条数
    loading: false, // 加载状态
    errMsg: '' // 错误信息
}

export default function testReducer(state = initialState, action: any) {
    switch (action.type) {
        case SET_USERLIST:
            return {
                ...state,
                loading: true
            }
        case USRE_SUCCESS:
            return {
                ...state,
                userList: action.payload.data,
                total: action.payload.count,
                loading: false
            }
        case USRE_ERROR:
            return {
                ...state,
                loading: false,
                errMsg: '接口错误'
            }
        default:
            return state
    }
}
